<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/themes/icon.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<script	src="${pageContext.request.contextPath}/js/jquery.backstretch.js"></script>
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
<title>Insert title here</title>
</head>
<script type="text/javascript">

//配置清空事件
function clearText() {
	$("#updateDept").form('clear');
}
//配置修改表单提交事件
function updateText() {
	$("#updateDept").form('submit');
}
//配置修改按钮事件

 function updateForm() {

	 var d_name= $("#update").val();
	
	   $.ajax({
		   //配置参数
		   //请求方式
		   type:'post',
		   //需要发起的请求
		   url:'${pageContext.request.contextPath}/select_updateDept',
		   //需要带什么数据过去
		   data:{'d_name':d_name},
		   //定义返回的数据类型
		   dataType:"json",
		   //请求成功时调用的函数(回调函数)
		   success:function(data){
			 if(data=="0"){
				 $('#updateDepts').dialog('close');
				 $.messager.alert('我的消息','不存在部门！！！')
				 $("#update").val("");

			 }else{
				 $('#updateDepts').dialog('open');
				 $("#updateDept").form('load',data)
			 }   	
		   }
	      
	   });
	
};

//配置日期文本框
function myformatter(date){
    var y = date.getFullYear();
    var m = date.getMonth()+1;
    var d = date.getDate();
    return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
    if (!s) return new Date();
    var ss = (s.split('-'));
    var y = parseInt(ss[0],10);
    var m = parseInt(ss[1],10);
    var d = parseInt(ss[2],10);
    if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
        return new Date(y,m-1,d);
    } else {
        return new Date();
    }
}
   $(function(){
	   
	   //配置日期框不输入文字
		$('#dd').datebox({    
		    required:true ,
		    editable:false
		}); 
		

		 //配置搜索框
		 $('#searchBox').searchbox({ 
			 searcher:function(value,name){ 
				 var dept_name = value;
				 
			  		$('#tb').datagrid('reload',{
			  			searchname:dept_name,
			  	
			  			   
			  			
			  		});
			      }, 
			 });
		 
			//配置表格
		    $('#tb').datagrid({    
			    url:'${pageContext.request.contextPath}/findDept',    
			    columns:[[   
	                
			        {field:'dept_id',title:'部门id',width:100,hidden:true},    
			        {field:'dept_name',title:'部门名字',width:362},    
			        {field:'dept_describe',title:'部门描述',width:362}, 
			        {field:'dept_temp',title:'temp',hidden:true,width:100}, 
			        {field:'dept_createtime',title:'创建时间',width:362}, 
			        {field:'dept_isdel',title:'是否删除',width:100,hidden:true,align:'right'}    
			    ]],
			    onLoadError: function(){
		            $.messager.alert('提示','没有符合条件的搜索结果！');
		        },
			     striped:true,
		         pagination:true,
		         
		 });
	   
	   //默认修改表单是隐藏的
	   $('#updateDepts').dialog('close');
		
	 //配置修改表单
		$("#updateDept").form({
			url:'${pageContext.request.contextPath}/updateDept',
			success:function(data){
				if(data=="1"){
					$('#updateDepts').dialog('close');
					$("#updateDepts").form('clear');
					$.messager.alert('我的消息','修改成功！！')
					 $("#update").val("");
					$('#tb').datagrid('reload');
				 }else if(data=="0"){
					 $('#updateDepts').dialog('close');
					 $("#updateDepts").form('clear');
					 $.messager.alert('我的消息','修改失败！！')
					  $("#update").val("");
					 $('#tb').datagrid('reload');
				}
			}
		
		});
	 
   });
</script>
<body>
         <div style = "height:50px;width:200px;">
         <input type="textbox" class="form-control" id="update" placeholder="请输入部门名">
         </div>
         <div style = "height:50px;width:200px;margin-left:200px;margin-top:-50px;">
          <button type="button" onclick="updateForm()" class="btn btn-primary">修改部门</button>
         </div>
         
         
         
      
      
      
         
    <div id = "updateDepts" class="easyui-dialog" title="修改部门信息"
       style="background:#ccc;width:100%;max-width:400px;padding:30px 60px;">     
     <form id = updateDept method="post">    
        <center style="margin-bottom:20px">
                     部门名字:                 
            <input class="easyui-textbox"  data-options="required: true,missingMessage:'部门名必填'" name = "dept_name" style="width:50%;height:32px">
        </center>      
            <input type="hidden"  name = "dept_id">
        <center style="margin-bottom:20px">
                     部门描述:
            <input class="easyui-textbox" name = "dept_describe" style="width:50%;height:32px">
        </center>
        <center style="margin-bottom:20px">
                  创建时间:
            <input class="easyui-datebox" name = "dept_createtime" id="dd" style="width:50%;height:32px">
        </center>
       
        </form>  
        
       	<div style="text-align: center; padding: 5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="updateText()" style="width: 80px">提交</a> 

			<a href="javascript:void(0)" class="easyui-linkbutton"
				onclick="clearText()" style="width: 80px">清空</a> 
		</div></div>
		<input id="searchBox" type="hidden">
		<h2 align="center"style="color:#FFFFFF">部门信息表</h2>
		<table id="tb" rownumbers="true" fitColumns="true" singleSelect="true" ></table>
</body>
</html>